<%@ page language="java" pageEncoding="ISO-8859-1"%>

<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html:html lang="true">
  <head>
    <html:base />
    
    <title><bean:message bundle="UsuarioResources" key="jsp.title"/></title>

	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="">
	<meta http-equiv="description" content="">
	<link rel="stylesheet" type="text/css" href="../extjs/grid-examples.css" />
	<link rel="stylesheet" type="text/css" href="../css/basic.css">
	<link rel="stylesheet" type="text/css" href="../extjs/ext-all.css">
	<script type="text/javascript" src="../js/jquery.js"></script>
    <script type="text/javascript" src="../extjs/ext-base.js"></script>
    <script type="text/javascript" src="../extjs/ext-all.js"></script>
	<script type="text/javascript" src="../extjs/examples.js"></script>
    <script type="text/javascript" src="../js/objTree.js"></script>
	<script type="text/javascript" src="../js/util.js"></script>
	<script src="../js/masks.js" type="text/javascript" language="JavaScript"></script>
	<script type="text/javascript">
/*
		var registros;
		var store;
		var grid;

		Ext.onReady(function() {
			registros = Ext.data.Record.create([
		   		{name: 'codigo', mapping: 'codigo'},
		   		{name: 'nome'},
		   		{name: 'telefone'},
		   		{name: 'email'},
		   		{name: 'apelido'},
		   		{name: 'status'}
			]);

		    // create the Data Store
		    store = new Ext.data.Store({
		        // load using HTTP
		        url: '../Ajax/SearchUsuario.do',

		        // the return will be XML, so lets set up a reader
		        reader: new Ext.data.XmlReader({
		               // records will have an "Item" tag
		               record: 'registro',
		               id: 'codigo'
		           }, registros)
		    });

		    // create the grid
		    grid = new Ext.grid.GridPanel({
		        store: store,
		        columns: [
		            {header: "Nome", width: 400, dataIndex: 'nome', sortable: true},
		            {header: "Telefone", width: 100, dataIndex: 'telefone', sortable: true},
		            {header: "E-mail", width: 100, dataIndex: 'email', sortable: true},
		            {header: "Apelido", width: 100, dataIndex: 'apelido', sortable: true},
		            {header: "Status", width: 100, dataIndex: 'status', sortable: true}
		        ],
		        renderTo: 'usuarios-grid',
		        shadow: true,
		        width: 800
		    });

		    store.load();
		});
*/
	</script>

	<script type="text/javascript">
		function excluirUsuario(codigo, nome) {
			if (confirm('<bean:message bundle="UsuarioResources" key="jsp.confirm.excluirUsuario"/> ' + nome + ' ?')) {
				document.location.href = "../Usuario/ExcluirUsuario.do?codigo=" + codigo;
			}
		}
	</script>
	<link rel="stylesheet" type="text/css" href="../css/basic.css">
  </head>
 
  <body>
    <html:form action="/Usuario/SearchUsuario.do" method="POST" focus="nome">
      <table border="0">
        <tr>
          <td><bean:message bundle="UsuarioResources" key="jsp.label.apelido"/>:</td>
          <td><html:text property="apelido" size="15" /></td>
        </tr>
        <tr>
          <td><bean:message bundle="UsuarioResources" key="jsp.label.nome"/>:</td>
          <td><html:text property="nome" size="30" /></td>
        </tr>
        <tr>
          <td><bean:message bundle="UsuarioResources" key="jsp.label.email"/>:</td>
          <td><html:text property="email" size="30" /></td>
        </tr>
        <tr>
          <td><bean:message bundle="UsuarioResources" key="jsp.label.endereco"/>:</td>
          <td><html:text property="endereco" size="30" /></td>
        </tr>
        <tr>
          <td><bean:message bundle="UsuarioResources" key="jsp.label.cep"/>:</td>
          <td><html:text styleId="cep" property="cep" size="10" /></td>
        </tr>
        <tr>
          <td><bean:message bundle="UsuarioResources" key="jsp.label.telefone"/>:</td>
          <td><html:text styleId="telefone" property="telefone" size="15" /></td>
        </tr>
        <tr>
          <td><bean:message bundle="UsuarioResources" key="jsp.label.dataNascimento"/>:</td>
          <td><html:text styleId="dataNascimento" property="dataNascimento" size="10" /></td>
        </tr>
		<tr>
			<td>&nbsp;</td>
        	<td align="left"><br><html:submit value="Pesquisar"/></td>
        </tr>
      </table>
    </html:form>

   	<div id="usuarios-grid"></div>

    <logic:present name="list">
    	<table border="0" width="100%">
    		<tr>
    			<td><bean:message bundle="UsuarioResources" key="jsp.label.codigo"/></td>
    			<td><bean:message bundle="UsuarioResources" key="jsp.label.nome"/></td>
    			<td><bean:message bundle="UsuarioResources" key="jsp.label.telefone"/></td>
    			<td><bean:message bundle="UsuarioResources" key="jsp.label.email"/></td>
    			<td><bean:message bundle="UsuarioResources" key="jsp.label.apelido"/></td>
    			<td><bean:message bundle="UsuarioResources" key="jsp.label.status"/></td>
    			<td><bean:message bundle="UsuarioResources" key="jsp.label.acao"/></td>
    		</tr>

    		<logic:iterate name="list" id="usuarioDTO">
	    		<tr>
	    			<td><bean:write name="usuarioDTO" property="codigo"/></td>
	    			<td><bean:write name="usuarioDTO" property="nome"/></td>
	    			<td><bean:write name="usuarioDTO" property="telefone"/></td>
	    			<td><bean:write name="usuarioDTO" property="email"/></td>
	    			<td><bean:write name="usuarioDTO" property="apelido"/></td>
	    			<td><logic:equal name="usuarioDTO" property="status" value="A">
	    					<bean:message bundle="UsuarioResources" key="jsp.label.ativo"/>
	    				</logic:equal>
	    				<logic:equal name="usuarioDTO" property="status" value="I">
	    					<bean:message bundle="UsuarioResources" key="jsp.label.inativo"/>
	    				</logic:equal>
	    			</td>
	    			<td>
	        			<a href="../Usuario/PrepareEditarUsuario.do?codigo=<bean:write name="usuarioDTO" property="codigo"/>"><img src="../images/edit_icon.gif" border="0" alt="<bean:message bundle="UsuarioResources" key="jsp.alt.edit"/> <bean:write name="usuarioDTO" property="apelido"/>"/></a>
	        			&nbsp;&nbsp;
	        			<a href="javascript:excluirUsuario(<bean:write name="usuarioDTO" property="codigo"/>, '<bean:write name="usuarioDTO" property="apelido"/>');"><img src="../images/delete_icon.gif" border="0" alt="<bean:message bundle="UsuarioResources" key="jsp.alt.delete"/> <bean:write name="usuarioDTO" property="apelido"/>"/></a>
	        		</td>
	    		</tr>
    		</logic:iterate>
    	</table>
    </logic:present>

<br/><br/>
<!-- <a href="../Login/Login.do">Voltar</a>  -->

<script language="JavaScript" type="text/javascript">
	var dateMask = new Mask("dd/mm/yyyy", "date");
	dateMask.attach(document.getElementById("dataNascimento"));

	var telMask = new Mask("(##) ####-####");
	telMask.attach(document.getElementById("telefone"));

	var cepMask = new Mask("#####-###");
	cepMask.attach(document.getElementById("cep"));
</script>

  </body>
</html:html>
